package com.gmall.rabbitmq.producer.controller;

import com.gmall.rabbitmq.config.RabbitMQConfig_Direct;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("direct")
public class DirectExchangeController {

    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("string/{routingKey}")
    public String producerMessage(@PathVariable String routingKey){

        rabbitTemplate.convertAndSend(RabbitMQConfig_Direct.Exchange_Direct_1,
                routingKey,"Hello 2109A");

        return "OK";
    }

    @GetMapping("map/{routingKey}")
    public String producerMapMessage(@PathVariable String routingKey){


        Map map = new HashMap<>();
        map.put("name","张三");
        map.put("age",20);
        rabbitTemplate.convertAndSend(RabbitMQConfig_Direct.Exchange_Direct_1,
                routingKey,map);

        return "OK";
    }
}
